home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
graphics
/
bgires.zip
/
BGIRES.DOC
next >
Wrap
Text File
|
1994-06-03
|
8KB
|
179 lines
BGIRES version 1.0 - TP 6.0 unit to store .BGI files in a resource file.
Written for the public domain by D.J. Murdoch, July, 1992
Description:
Graphics programs written in Borland languages can take advantage of
"BGI" drivers - Borland's standard graphics interface. This lets them
be nearly device independent, since all driver-specific code is kept
in the .BGI files, and a standard interface is used to access it.
When you want to distribute one of these programs, one option is to
distribute multiple .BGI files with your program - but that's messy.
You also have the option of linking several of them into the .EXE
file. (Turbo Pascal comes with instructions on how to do this;
Borland even provides a BGILINK.MAK makefile to automate it for you,
in TP 6.0.) The trouble with this option is that the BGI drivers can't
be overlaid, so they take up valuable RAM space. Since you only ever
need one of them, that's a waste.
BGIRES offers a solution to these problems. It lets you put the .BGI
files into a "resource file", and only load one of them from there
into RAM. Since TP 6.0 allows you to attach a resource file to your
.EXE file, this is the best of both worlds: you distribute only one
file, and only one BGI driver takes up RAM space.
Interfaced Procedures and Functions
procedure ResInitGraph(var graphdriver,graphmode:integer;
var resfile:TResourcefile;
pathtodriver:string);
Attempts to load the given driver (which may be Detect) from the
resource file, register it, and call initgraph. PathToDriver will
only be used if the driver isn't in the resource file.
function PutDriver(filename:string;var resfile:TResourcefile;
keep:boolean):integer;
Puts driver 'filename' into the given resource file. If keep is true,
leaves it loaded in memory. If keep is false, deletes it from memory.
Unfortunately, this leaves Graph thinking it's still there, and is
rather dangerous. I think it would be safe to set keep to false if it
didn't correspond to the current graphics hardware, but I'm not sure.
Returns a graphics error constant if something goes wrong.
function PutAllDrivers(path:string;var resfile:TResourcefile;
keep:boolean):integer;
Puts all the standard drivers into the given resource file; assumes
that it can find them all in the given path (terminated with a
backslash, e.g. "c:\drivers\"). Returns all graphics error constants
from PutDriver or'd together. I can't think of any use for the value,
other than to check for 0 or non-zero.
procedure DelDriver(Graphdriver:integer;var resfile:TResourcefile);
Deletes the driver with the given number from the resource file.
Numbers are those used by InitGraph, i.e. CGA=1, VGA=9, etc. This
doesn't save any space; to recover the space from the deleted driver,
you need to pack the resource file.
NB: Some drivers handle several devices, so for example deleting VGA
will also take out EGA. The standard list is:
File Graphdriver constants
CGA.BGI: CGA, MCGA
EGAVGA.BGI: EGA, EGA64, EGAMono, VGA
IBM8514.BGI: IBM8514
HERC.BGI: HercMono
ATT.BGI: ATT400
PC3270.BGI: PC3270
Interfaced Types
PResourcefile2 = ^TResourcefile2;
TResourcefile2 = object(TResourcefile)
A resource file that knows how to pack itself. The standard resource
files require you to fiddle around with Switchto, and generally sweat
a lot; this one has all that already done for you. It needs temporary
space to work in, and will take RAM, EMS, XMS or disk, depending on
what's available, since it uses a TempStream from my Streams unit.
The downside of all this convenience is that it pulls in a fair bit of
code (about 4K) if you use Pack and don't use TempStream anywhere else.
This really belongs in the Streams or Objects unit; it will be moved
there in future versions.
Note: If you don't have the Streams unit, you won't be able to compile
BGIRES as distributed; however, I've put in some conditional compiling
directives which will make it work if you define NOSTREAMS.
procedure TResourceFile2.Pack;
Packs in place. This works even if the resource file is embedded in
a larger file, e.g. an .EXE file with overlays and resources. Note
that whatever follows the resource file will be moved; something
like the overlay manager would need to be reinitialized afterwards.
PBGIDriver = ^TBGIDriver;
Tbgidriver = object(TObject)
This object manages the memory used by the .BGI driver. You probably
never need to use it yourself; the procedures and functions above do
everything necessary. The fields and methods are commented in the
source.
Interfaced Constants
All of the typed constants in BGIRES are declared in separate const
blocks. This means that if you somehow don't need all of them, they
won't be linked into your final program.
drivernum : array[1..10] of word = (0,0,1,1,1,2,3,4,1,5);
These are the internal driver numbers for graphdriver values 1 to 10.
BGI files keep two sets of numbers: the driver number (0 to 5 for the
standard ones), and the graphdriver values (1 to 10, i.e. CGA to
PC3270). This array lets you do the translation.
drivernames : array[0..5] of String[11] =
('CGA.BGI', 'EGAVGA.BGI', 'IBM8514.BGI',
'HERC.BGI', 'ATT.BGI', 'PC3270.BGI');
These are the filenames corresponding to the internal driver numbers.
BGITypeCode = $4247; { 'BG' }
This is the object type code used within the resource file. It may
collide with the object type code you choose for your own objects; if
so, you can change it to whatever you like.
RBGIDriver : TStreamRec = ( blah blah blah );
A stream registration record is set up to make registration easy.
Since there's not much use in using this unit without registering the
TBGIDriver type, it gets automatically registered in the startup code.
Examples
Take a look through the sample code in Demo.pas. This program does
the following:
- it declares itself as the resource file
- if there aren't any .BGI drivers on the end of DEMO.EXE (as there
won't be on the first run through), it adds as many as it can find
in the path given on the command line
- it deletes all of them except the one corresponding to the current
video board, and shrinks itself back as much as possible.
- it gives a flashy ad for BGIRES, which is nearly readable, but
probably runs at the wrong speed on your machine.
License
Hey, didn't you RTFM? Up at the top, it says this is public domain.
I mean it: it's free. That's the good news. The bad news, of
course, is that I can't guarantee that it'll work for you; for all I
know, it might make your monitor blow up (or as I read in a disclaimer
on Usenet the other day, turn your chair into antimatter :-).
Still, if you do find any bugs, I'd like to hear about them. Send me
mail, to one of the following addresses (in order of decreasing
stability):
71631,122 on Compuserve
337 Willingdon Ave., Kingston, Ontario, Canada
DJ Murdoch at 1:249/1.5 on Fidonet
dmurdoch@mast.queensu.ca on Internet
Finally, if you have an overwhelming desire to pay for this software,
please donate $5 (or the equivalent in your local currency) to a local